home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 7
/
Apprentice-Release7.iso
/
Demos
/
A.D. Software
/
OOFILE 1.3b4d6.sit
/
OOFILE 1.3b4d6
/
MacCodeWarriorDemo1.3b4d6
/
docs
/
samples
/
ooftst06.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1997-03-17
|
3KB
|
95 lines
// Copyright 1994 A.D. Software. All Rights Reserved
// OOFTEST6
// this sample modifies related data
// including demonstrating the caching of related records
// as would typically be used in a GUI environment
// Simple stream I/O is used to interact with the user.
#include "oofile.h"
#include "ooftst02.h"
// global variables that define the database using the ooftst02 classes
TEST_CONNECT theDB;
dbPatients Patients;
dbVisits Visits;
dbRelationship PatientVisits(Patients.Visits, Visits.Patient);
int main()
{
cout << "OOFILE Validation Suite - Test 6\n"
<< "Simple test to demonstrate updating related fields" << endl
<< "using the database from ooftst02" << endl;
#ifdef TESTING_DBASE
#ifdef _Macintosh
const char* kExistsName = ":ooftst06:Patients.dbf";
const char* kDatabaseName = ":ooftst06:";
#else
const char* kExistsName = "Patients.dbf"
const char* kDatabaseName = "";
#endif
#else
const char* kDatabaseName = "ooftst06.db";
const char* kExistsName = kDatabaseName;
#endif
if (dbConnect::fileExists(kExistsName)) {
theDB.openConnection(kDatabaseName);
}
else {
theDB.newConnection(kDatabaseName);
Patients.AddTestData();
}
dbView smithVisits(Patients.Visits);
smithVisits << Patients.Visits->VisitDate << Patients.Visits->Why;
Patients.search(Patients.LastName=="Smith");
cout << "Dumping Smith and his visits: " << endl
<< Patients << endl
<< smithVisits << endl;
cout << "changing the first reason to 'Computer-Induced Sanity' " << endl;
Patients.Visits->gotoRecord(0);
Patients.Visits->Why = "Computer-Induced Sanity";
cout << "changing the second reason to 'Funny Views' " << endl;
smithVisits.source()->gotoRecord(1); // test navigating via the view
Patients.Visits->Why = "Funny Views";
Patients.saveRecord(); // save both changes
cout << "Dumping Smith and changed visits: " << endl
<< Patients << endl
<< smithVisits << endl;
Patients.AddVisit("14/2/1995", "Anxiety Attacks");
// now change to another related record - our new one should be cached
smithVisits.source()->gotoRecord(1);
Patients.Visits->Why = "Changed Again";
// return to the new record (in the cache) and update it
smithVisits.source()->gotoRecord(2);
Patients.Visits->VisitDate = "15/2/1994";
Patients.saveRecord();
cout << "Dumping Smith and visits with added visit: " << endl
<< Patients << endl
<< smithVisits << endl;
cout << "Now dumping the entire Visits file: " << endl << Visits;
cout << "done" << endl;
return EXIT_SUCCESS;
}